# -*- coding: utf-8 -*-
#coding=utf-8

import config
from log import log

import action.admin
import action.ajax
import action.user
import action.index

#Mandatory urls
urls = [
    '/admin',               action.admin.indexAction,
    '/admin/login',         action.admin.login.indexAction,
    '/admin/login/(.*)',    action.admin.login.refererAction,
    '/admin/logout',        action.admin.logout.indexAction,
    '/admin/logout/(.*)',   action.admin.logout.refererAction,
    '/admin/install',       action.admin.install.indexAction,
    '/admin/install/(.*)',  action.admin.install.refererAction,
    '/admin/upload',        action.admin.upload.indexAction,
    '/admin/upload/(.*)',   action.admin.upload.refererAction,
    '/',                    action.index.indexAction,
    '/user',                action.user.indexAction,
    '/user/login',         action.user.login.indexAction,
    '/user/login/(.*)',    action.user.login.refererAction,
    '/user/logout',        action.user.logout.indexAction,
    '/user/logout/(.*)',   action.user.logout.refererAction,
    '/user/upload',        action.user.upload.indexAction,
    '/user/upload/(.*)',   action.user.upload.refererAction,

    # ajax views, exports  and actions
    '/ajax/views/(.*)',   action.ajax.views,
    '/ajax/exports/(.*)',   action.ajax.exports,
    '/ajax/actions/(.*)',   action.ajax.actions,
]


def fillAdminUrls():
    for m in config.MODULES['admin']:
        if not m['disabled'] and m['module']:
            url = '/admin/%s' % m['module']
            action = 'action.admin.%s.indexAction' % m['module']
            urls.append(url)
            urls.append(action)

            url = '/admin/%s/(.*)' % m['module']
            action = 'action.admin.%s.refererAction' % m['module']
            urls.append(url)
            urls.append(action)

def fillUserUrls():
    for m in config.MODULES['user']:
        if not m['disabled'] and m['module']:
            url = '/user/%s' % m['module']
            action = 'action.user.%s.indexAction' % m['module']
            urls.append(url)
            urls.append(action)

            url = '/user/%s/(.*)' % m['module']
            action = 'action.user.%s.refererAction' % m['module']
            urls.append(url)
            urls.append(action)

fillAdminUrls()
fillUserUrls()

if config.DEBUG: log.debug('Webpy url mapping: %s' % str(urls));
